package me.hl.rxjava;

import org.junit.Test;
import rx.Observable;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by haoliang on 2016/6/6.
 */
public class RxjavaDemo {
    @Test
    public void start() {
        Observable.just("hello,world")
                .map(s -> s + "   -planck")
                .subscribe((s) -> System.out.print(s));

    }

    @Test
    public void formDemo() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(String.valueOf(i));
        }
        //循环输出
        System.out.println("输出:");
        Observable.just(list)
                .flatMap(b -> Observable.from(b))
                .subscribe(a -> System.out.print(a));
        System.out.println("相等:");
        //等于
        Observable.from(list)
                .subscribe(a -> System.out.print(a));
        System.out.println("过滤:");
        //还可以有过滤
        Observable.from(list)
                .filter(a -> !a.equals("2"))
                .take(5)
                .subscribe(a -> System.out.print(a));
    }


}
